import java.util.Arrays;

public class SeqList {
    public int[] elem;
    public int usedSize;//计数器
    public static int capacity = 10;
    public SeqList() {
        this.elem =new int[capacity];
    }
    public boolean isfull() {
        return this.usedSize == capacity;
    }

    public boolean isempty() {
        return this.usedSize == 0;
    }
    // 打印顺序表
    //只展示计数器内部的
    public void print() {
        for (int i = 0; i < this.usedSize; i++) {
            System.out.println(elem[i]);
        }
    }

    // 在 pos 位置新增元素
public void add(int pos , int num) {
        if(isfull() == true) {
            Arrays.copyOf(this.elem,2*capacity);
        }
    for (int i = usedSize-1; i >= pos ; i--) {
        elem[i+1] = elem[i];
    }
    elem[pos] = num;
    this.usedSize++;
}
    // 判定是否包含某个元素
public boolean iscontain(int num) {
        if(isempty() == true) {
            return false;
        }
    for (int i = 0; i < usedSize; i++) {
        if(elem[i] == num) {
            return true;
        }
    }
    return false;
}

    // 查找某个元素对应的位置
public int  toFind(int num) {
        if(isempty() == true) {
            return -1;
        }
    for (int i = 0; i < this.usedSize; i++) {
        if(this.elem[i] == num) {
            return i;
        }
    }
    return -1;
}

// 获取 pos 位置的元素

    public int get(int pos) {
        if(isempty() == true) {
            return-1;
        }
        for (int i = 0; i < this.usedSize; i++) {
            if(this.elem[i] == this.elem[pos]) {
                return elem[i];
            }
        }
        return -1;
    }
// 给 pos 位置的元素设为 value
public void change(int pos , int value) {
        if(pos <0 || pos > this.usedSize) {
            System.out.println("错误");
            return;
        }
        elem[pos] = value;
}
//删除第一次出现的关键字key
    public void dele(int key) {
        int index = toFind(key);
        if(isempty() == true) return;
        if(index == -1) {
            System.out.println("没有");
        }
        for (int i = index; i < this.usedSize-1; i++) {
            elem[i] = elem[i+1];
        }
        this.usedSize--;
    }
// 获取顺序表长度
public int getlength() {
        return this.usedSize;
}
// 清空顺序表
    public void clear() {
        for (int i = 0; i < this.usedSize; i++) {
            elem[i] = 0;
        }
        this.usedSize = 0;
    }


}
